import request from "@/utils/request";

// 获取资源类型列表
export function getResourceTypes() {
  return request({
    url: "/resources/list_types",
    method: "get",
  });
}

// 获取资源状态列表
export function getResourceStatus() {
  return request({
    url: "/resources/list_status",
    method: "get",
  });
}

// 获取扩容类型列表
export function getCapacityModes() {
  return request({
    url: "/resources/list_capacity_modes",
    method: "get",
  });
}

// 查询资源列表
export function listResource() {
  return request({
    url: "/resources/list",
    method: "get",
  });
}

// 搜索资源
export function searchResources(query) {
  return request({
    url: "/resources/search",
    method: "post",
    data: query,
  });
}

// 查询资源详细
export function getResource(resourceId) {
  return request({
    url: "/resources/details/" + resourceId,
    method: "get",
  });
}

// 上传依赖文件
export function uploadRequirements(file) {
  const formData = new FormData();
  formData.append("file", file);
  return request({
    url: "/resources/upload",
    method: "post",
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}

// 新增资源
export function addResource(data) {
  return request({
    url: "/resources/add",
    method: "post",
    data: data,
  });
}

// 修改资源
export function updateResource(resourceId, data) {
  return request({
    url: "/resources/update/" + resourceId,
    method: "put",
    data: data,
  });
}

// 删除资源
export function delResource(resourceId) {
  return request({
    url: "/resources/" + resourceId,
    method: "delete",
  });
}

// 批量删除资源
export function delResourceBatch(resourceIds) {
  return request({
    url: "/resources/delete_many",
    method: "delete",
    data: resourceIds,
  });
}

// 启动资源
export function startResource(resourceId) {
  return request({
    url: "/resources/start/" + resourceId,
    method: "post",
  });
}

// 停止资源
export function stopResource(resourceId) {
  return request({
    url: "/resources/stop/" + resourceId,
    method: "post",
  });
}

// 扩容资源
export function replicateResource(resourceId, data) {
  return request({
    url: "/resources/replicate/" + resourceId,
    method: "post",
    data: data,
  });
}
